package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
@Api(tags = "资源菜单管理")
public class RescourceController {

    @Autowired
    private ResourceService resourceService;

    @PostMapping("/list")
    @ApiOperation("资源列表")
    public ResponseResult<List<ResourceVo>> list(@RequestBody ResourceDto resourceDto){
        List<ResourceVo> list = resourceService.list(resourceDto);
        return ResponseResult.success(list);
    }

    @PostMapping("/tree")
    @ApiOperation("资源树形")
    public ResponseResult<List<ResourceVo>> tree(@RequestBody ResourceDto resourceDto){
        return ResponseResult.success(resourceService.tree(resourceDto));
    }

    @PutMapping
    @ApiOperation("资源添加")
    public ResponseResult addResource(@RequestBody ResourceDto resourceDto){
        resourceService.addResource(resourceDto);
        return ResponseResult.success(true);
    }

    @PatchMapping
    @ApiOperation("资源修改")
    public ResponseResult updateResource(@RequestBody ResourceDto resourceDto){
        resourceService.updateResource(resourceDto);
        return ResponseResult.success(true);
    }

    @PostMapping("/enable")
    @ApiOperation("资源启用禁用")
    public ResponseResult<Boolean> ResourceStatus(@RequestBody ResourceDto resourceDto){
        return ResponseResult.success(resourceService.ResourceStatus(resourceDto));
    }

    @DeleteMapping("/{resourceNo}")
    @ApiOperation("删除菜单")
    public ResponseResult deleteResource(@PathVariable String resourceNo){
        resourceService.deleteResource(resourceNo);
        return ResponseResult.success();
    }

}


























